Database db;
Application app;
DateFormat dateformat = new SimpleDateFormat("dd/MM/yyyy HH:mm");
PFont font1;
PFont font2;
PFont font1bold;
int SCRWIDTH = 1000;
int SCRHEIGHT = 600;
PImage navbg;
PImage nav1;
PImage nav2;
PImage nav3;
PImage nav4;
PImage nav5;
PImage loadingImg;
int mouseCursor = 0;
boolean loaded = false;
int scrW;
int scrH;

// 09/04/2009 Bagdat
void setup()
{
  scrW = SCRWIDTH;
  scrH = SCRHEIGHT;
  
  // load images
  font1 = loadFont("ArialMT-12.vlw");
  font1bold = loadFont("Arial-BoldMT-12.vlw");
  font2 = loadFont("ArialMT-24.vlw");
  navbg = loadImage("navbg.jpg");
  nav1 = loadImage("nav1.jpg");
  nav2 = loadImage("nav2.jpg");
  nav3 = loadImage("nav3.jpg");
  nav4 = loadImage("nav4.jpg");
  nav5 = loadImage("nav5.jpg");
  loadingImg = loadImage("loading.jpg");
  
  addMouseWheelListener(new java.awt.event.MouseWheelListener()
  { 
    public void mouseWheelMoved(java.awt.event.MouseWheelEvent evt)
    { 
      mouseWheel(evt.getWheelRotation());
    }
  }); 
  
  // create window
  size(scrW, scrH);
  
  db = new Database();
  Thread thread = new Thread(db);
  thread.start();
}

void draw()
{
  scrW = width;
  scrH = height;
  if(loaded)
  {
    app.draw();
  }
  else
  {
    image(loadingImg, 0, 0);
    noStroke();
    fill(255, 200);
    if(db.numRecords > 0)
    {
      rect(203, 488, 594 * db.loadedRecords / db.numRecords, 24);
      textFont(font1);
      String out = db.loadedRecords + " / " + db.numRecords;
      text(out, 798 - (int)textWidth(out), 530);
      text(100 * db.loadedRecords / db.numRecords + " %", 203, 530);
    }
    if(db.loaded)
    {
      app = new Application();
      loaded = true;
      frame.setResizable(true);
    }
  }
}

void mouseWheel(int delta)
{
  if(app != null)
  {
    if(app.activeForm == app.graphForm)
    {
      db.qryIntervals += delta;
      app.graphForm.setActive();
    }
  }
}

